package com.wangdao.wechatmall.controller.wx;

import com.wangdao.wechatmall.bean.bo.wx.BaseCommentBO;
import com.wangdao.wechatmall.bean.bo.wx.BaseCommentListBO;
import com.wangdao.wechatmall.bean.bo.wx.WxCommentPostBO;
import com.wangdao.wechatmall.bean.pojo.User;
import com.wangdao.wechatmall.bean.vo.admin.BaseRespVo;
import com.wangdao.wechatmall.bean.vo.wx.CommentCountVO;
import com.wangdao.wechatmall.bean.vo.wx.CommentListVO;
import com.wangdao.wechatmall.bean.vo.wx.WxCommentPostVO;
import com.wangdao.wechatmall.mapper.UserMapper;
import com.wangdao.wechatmall.service.WXCommentService;
import com.wangdao.wechatmall.service.admin.CommentService;
import com.wangdao.wechatmall.util.WXSystemUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ShuiYi
 * @time 2021-07-12 16:09
 */
@RestController
@RequestMapping("wx")
public class WXCommentController {

    @Autowired
    WXCommentService wXCommentService;

    @RequestMapping("comment/count")
    public BaseRespVo count(BaseCommentBO baseCommentBO) {
        CommentCountVO commentCountVO = wXCommentService.count(baseCommentBO);
        return BaseRespVo.ok(commentCountVO);
    }

    @RequestMapping("comment/list")
    public BaseRespVo list(BaseCommentListBO baseCommentListBO) {

        CommentListVO commentListVO = wXCommentService.list(baseCommentListBO);
        return BaseRespVo.ok(commentListVO);
    }
    @Autowired
    UserMapper userMapper;
    @RequestMapping("comment/post")
    public BaseRespVo post(@RequestBody  WxCommentPostBO wxCommentPostBO) {

        String username = (String) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();

        Integer id = userMapper.queryId(username);
        WxCommentPostVO wxCommentPostVO = wXCommentService.post(wxCommentPostBO, id);
        return BaseRespVo.ok(wxCommentPostVO);
    }
}
